package com.key.web_admin.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.key.common.base.RespResult;
import com.key.modules.dto.SysUserSelectDTO;
import com.key.modules.entity.SysRole;
import com.key.modules.entity.SysUser;
import com.key.modules.service.SysUserService;
import com.key.modules.vo.SysUserVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author：朕
 * @Package：com.key.web_admin.controller
 * @Project：logistics_system
 * @name：SysUserController
 * @Date：2023/3/23 19:56
 * @Filename：SysUserController
 */
@RestController
@RequestMapping("/systemSetting/user")
public class SysUserController {

    @Autowired
    private SysUserService sysUserService;

    /**
     * 显示所有用户
     */
    @GetMapping("/findSysUser")
    public List<SysUserVO> findSysUser(SysUserSelectDTO sysUserSelectDTO){
        return sysUserService.findSysUser(sysUserSelectDTO);
    }

    /**
     * 新增用户
     */
    @PostMapping("/addSysUser")
    public RespResult addSysUser(SysUser sysUser){
        Boolean s = sysUserService.addSysUser(sysUser);
        if(s==true){
            return RespResult.success();
        }
        return RespResult.error("添加失败");
    }

    /**
     * 修改用户
     */
    @PostMapping("/updateSysUser")
    public RespResult updateSysUser(SysUser sysUser){
        Boolean s = sysUserService.updateSysUser(sysUser);
        if(s==true){
            return RespResult.success();
        }
        return RespResult.error("修改成功");
    }

    /**
     * 删除用户
     */
    @PostMapping("/deleteSysUser")
    public RespResult deleteSysUser(Integer userId){
        Boolean s = sysUserService.deleteSysUser(userId);
        if(s==true){
            return RespResult.success();
        }
        return RespResult.error("删除失败");
    }
    /**
     * 新增用户角色
     */
    @PostMapping("/addSysUserRole")
    public RespResult addSysUserRole(Integer userId,Integer[] roleId){
        boolean s = sysUserService.addSysUserRole(userId,roleId);
        if(s==true){
            return RespResult.success();
        }
        return RespResult.error("添加失败");
    }


}
